package com.blog.service.impl;

import com.blog.dao.MessageDao;
import com.blog.dao.impl.MessageDaoImpl;
import com.blog.pojo.Message;
import com.blog.service.MessageService;

import java.util.List;

public class MessageServiceImpl implements MessageService {
    private MessageDao messageDao=new MessageDaoImpl();
//添加消息
    @Override
    public Message addMessage(Message message) {
        messageDao.addMessage(message);
        return message;

    }
//删除消息
    @Override
    public boolean deleteMessage(int id) {
        int delete = messageDao.deleteMessage(id);
        if (delete>0){
            return true;
        }
        return false;
    }
//查询已发送信息
    @Override
    public List<Message> findMessageBySenderId(int userId) {
        return messageDao.findMessageBySenderId(userId);
    }
//查询已接收信息
    @Override
    public List<Message> findMessageByReceiveId(int userId) {
        return messageDao.findMessageByReceiveId(userId);
    }
//判断是否已单独发送一条信息
    @Override
    public boolean countSenderRecevier(int senderId, int receiveId) {
        return messageDao.countSenderRecevier(senderId,receiveId);
    }
//查询A和B的全部信息
    @Override
    public List<Message> findMessageBySenderAndReceiver(int senderId, int receiveId) {
        return messageDao.findMessageBySenderAndReceiver(senderId,receiveId);
    }
//判断A和B是否互相关注
    @Override
    public long followeeSenderReceiver(int senderId, int receiveId) {
        return messageDao.followeeSenderReceiver(senderId,receiveId);
    }
//修改已读状态
    @Override
    public boolean updateMessage(int id, byte isRead) {
        int update = messageDao.updateMessage(id,isRead);
        if (update>0){
            return true;
        }
        return false;
    }

    @Override
    public Message findById(int id) {
    return messageDao.findById(id);
    }
}
